package com.study.lxy.exames;

import java.util.ArrayList;
import java.util.List;

public class Test1 {


    public static void main(String[] args) {
        List<Rabbit> currentList = new ArrayList<Rabbit>();
        currentList.add(new Rabbit(0));
        for (int i = 1; i <= 50; i++) {
            rabbitIncress(currentList);
            int count = currentList.size();
            System.out.println("month : " + i + ",rabbit count = " + count);
        }
    }

    public static void rabbitIncress(List<Rabbit> rabbitList){

        List<Rabbit> newBirth = new ArrayList<Rabbit>();
        for(Rabbit rabbit : rabbitList){
            rabbit.ageIncress();
            if(rabbit.canBirth()){
                newBirth.add(new Rabbit(1));
            }
        }
        rabbitList.addAll(newBirth);
    }
    static class Rabbit{
        private int age = 0;
        public Rabbit(int age){
            this.age = age;
        }
        public boolean canBirth(){
            if(age >= 3){
                return true;
            }
            return false;
        }
        public void ageIncress(){
            age++;
        }
    }


}
